//
//  WSAlbumHeaderView.m
//  GroupFourFM
//
//  Created by 王鑫 on 15/12/23.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSAlbumHeaderView.h"
#import <UIImageView+WebCache.h>
#import <UIButton+WebCache.h>
#import <FXBlurView.h>

@interface WSAlbumHeaderView ()

@property (nonatomic, strong) UIImageView *backgroundImageView;
@property (nonatomic, strong) UIImageView *albumPic;
@property (nonatomic, strong) UILabel *authorName;
@property (nonatomic, strong) UILabel *albumDigest;
@property (nonatomic, strong) UIImageView *playIcon;
@property (nonatomic, strong) UILabel *playCount;
@property (nonatomic, strong) UIButton *avatarBtn;
@property (nonatomic, strong) FXBlurView *blurView;

@end

@implementation WSAlbumHeaderView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    
    return self;
}

- (void)createSubViews
{
    
    //背景
    self.backgroundImageView = [[UIImageView alloc]init];
    self.backgroundImageView.backgroundColor = [UIColor redColor];
    self.backgroundImageView.alpha = 1;
    [self addSubview:self.backgroundImageView];
    [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.height.mas_equalTo(SCREEN_HEIGHT * 0.6);
        
    }];
    
    UIVisualEffectView * blurView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
    [blurView setFrame:CGRectMake(0, self.frame.size.height - SCREEN_HEIGHT * 0.6, SCREEN_WIDTH, SCREEN_HEIGHT * 0.6)];
    [self addSubview:blurView];
    
    //专辑图片
    self.albumPic = [[UIImageView alloc] init];
    self.albumPic.backgroundColor = CLEAR;
    [self addSubview:self.albumPic];
    [self.albumPic mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(@30);
        make.left.mas_equalTo(@20);
        make.width.height.equalTo(self.mas_height).multipliedBy(0.5);

    }];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"placeholder_cell_same"];
    [self.albumPic addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    //主播头像
    self.avatarBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.avatarBtn.backgroundColor = CLEAR;
    self.avatarBtn.layer.masksToBounds = YES;
    self.avatarBtn.layer.cornerRadius = 15;
    [self.avatarBtn setImage:[UIImage imageNamed:@"placeholder_cell_cicle"] forState:UIControlStateNormal];
    [self addSubview:self.avatarBtn];
    [self.avatarBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.albumPic);
        make.left.equalTo(self.albumPic.mas_right).offset(20);
        make.height.width.equalTo(self.albumPic.mas_height).multipliedBy(0.3);
    }];
    
    //主播名字
    self.authorName = [[UILabel alloc] init];
    self.authorName.backgroundColor = CLEAR;
    self.authorName.textColor = WHITE;
    self.authorName.font = [UIFont systemFontOfSize:19 weight:1];
    [self addSubview:self.authorName];
    [self.authorName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(self.avatarBtn);
        make.left.equalTo(self.avatarBtn.mas_right).offset(10);
        make.right.equalTo(self.backgroundImageView).offset(-40);
    }];
    
    //专辑简介
    self.albumDigest = [[UILabel alloc] init];
    self.albumDigest.backgroundColor = CLEAR;
    self.albumDigest.font = [UIFont systemFontOfSize:16 weight:1];
    [self addSubview:self.albumDigest];
    self.albumDigest.textColor = [UIColor grayColor];
    [self.albumDigest mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.avatarBtn);
        make.top.equalTo(self.avatarBtn.mas_bottom).offset(5);
        make.height.equalTo(self.avatarBtn);
        make.right.equalTo(self.authorName);
    }];

}

- (void)setAlbumModel:(WSAlbumModel *)albumModel {

    _albumModel = albumModel;
    NSURL *urlBg = [NSURL URLWithString:_albumModel.coverLarge];
    [self.backgroundImageView sd_setImageWithURL:urlBg placeholderImage:PLACEHOLDER_IMAGE];
    NSURL *url = [NSURL URLWithString:_albumModel.coverSmall];
    [self.albumPic sd_setImageWithURL:url placeholderImage:PLACEHOLDER_IMAGE];
    self.authorName.text = _albumModel.nickname;
    self.albumDigest.text = _albumModel.intro;
    self.playCount.text = [NSString stringWithFormat:@"%ld",_albumModel.playtimes];
    NSURL *urlImg = [NSURL URLWithString:_albumModel.avatarPath];
    [self.avatarBtn sd_setImageWithURL:urlImg forState:UIControlStateNormal];
}

@end
